package freecomm.study.commonwidget;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.ToggleButton;

public class CommonWidget extends Activity
{
    private TextView nameTextView;
    private TextView pwTextView;
    private RadioGroup genderRadioGroup;
    private ToggleButton mageToggleButton;
    private CheckBox swimCheckBox;
    private CheckBox ballCheckBox;
    private Spinner postSpinner;
    private Button submitButton;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        nameTextView = (TextView) findViewById(R.id.nameTV);
        pwTextView = (TextView) findViewById(R.id.pwTV);
        genderRadioGroup = (RadioGroup) findViewById(R.id.genderRG);
        mageToggleButton = (ToggleButton) findViewById(R.id.mageTB);
        swimCheckBox = (CheckBox) findViewById(R.id.swimCB);
        ballCheckBox = (CheckBox) findViewById(R.id.ballCB);
        postSpinner = (Spinner) findViewById(R.id.postSP);
        submitButton = (Button) findViewById(R.id.submitBtn);
        String[] str =
        { "Student", "Teacher" };
        ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, str);
        postSpinner.setAdapter(aa);
        submitButton.setOnClickListener(new OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                // TODO Auto-generated method stub
                Bundle b = new Bundle();
                b.putString("name", "name:" + nameTextView.getText().toString());
                b.putString("pw", "password:" + pwTextView.getText().toString());
                if (0 == genderRadioGroup.getCheckedRadioButtonId())
                {
                    b.putString("gender", "gender:male");
                } else
                {
                    b.putString("gender", "gender:female");
                }
                if (mageToggleButton.isChecked())
                {
                    b.putString("marriage", "marriage:yes");
                } else
                {
                    b.putString("marriage", "marriage:no");
                }
                String mInterest = "interest:";
                if (swimCheckBox.isChecked())
                {
                    mInterest += "swiming";
                }
                if (ballCheckBox.isChecked())
                {
                    mInterest += ",basketball";
                }
                b.putString("interest", mInterest);
                b.putString("post", "position:" + postSpinner.getSelectedItem().toString());
                Intent intent = new Intent(CommonWidget.this,Result.class);
                intent.putExtra("data", b);
                startActivity(intent);
            }
        });

    }
}